﻿@model Guid
<div id="filter-container">

    
        <strong>Сортировать</strong>
        @Ajax.ActionLink("по артикулу", "ShowListByCategory","Product", new { categoryId = Model, brendId = ViewData["BrendId"], filter = 1 }, new AjaxOptions { UpdateTargetId = "product-list-container" }, new { @class = "sort button" })
        @Ajax.ActionLink("по цене", "ShowListByCategory","Product", new { categoryId = Model, brendId = ViewData["BrendId"], filter = 3 }, new AjaxOptions { UpdateTargetId = "product-list-container" }, new { @class = "sort button" })
        @Ajax.ActionLink("по дате", "ShowListByCategory", "Product", new { categoryId = Model, brendId = ViewData["BrendId"], filter = 5 }, new AjaxOptions { UpdateTargetId = "product-list-container" }, new { @class = "sort button" })
   
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $(".sort").live("click", function () {
            var link = $(this).attr('href');
            var equalPosition = link.indexOf('filter='); //Get the position of '='
            var strNumber = link.substring(equalPosition + 7, link.length);

            var number = parseInt(strNumber);
            $.each($(".sort"), function () {
                $(this).removeClass("up-sort");
                $(this).removeClass("down-sort");
            })
            if (number % 2 == 0) {
                //чет
                number = number - 1;
                $(this).attr('href', link.substring(0, equalPosition + 7) + number.toString());
                //                $.each($(".paging"), function () {
                //                    var pagingLink = $(this).attr('href');
                //                    $(this).attr('href', pagingLink + '&filter=' + number.toString());
                //                });
                $(this).addClass("down-sort");
                $(".sort").button({
                    icons: {
                        secondary: null
                    }
                });
                $(".down-sort").button({
                    icons: {
                        secondary: "ui-icon-triangle-1-s"
                    }
                });
            }
            else {
                number = number + 1;
                $(this).attr('href', link.substring(0, equalPosition + 7) + number.toString());
                //                $.each($(".paging"), function () {
                //                    var pagingLink = $(this).attr('href');
                //                    $(this).attr('href', pagingLink + '&filter=' + number.toString());
                //                });
                $(this).addClass("up-sort");
                $(".sort").button({
                    icons: {
                        secondary: null
                    }
                });
                $(".up-sort").button({
                    icons: {
                        secondary: "ui-icon-triangle-1-n"
                    }
                });
            }
        });
    });
</script>
